<template>
<div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="原密码" prop="oldPass">
            <el-input v-model="ruleForm.oldPass"></el-input>
        </el-form-item>
        <el-form-item label="新密码" prop="newPass">
            <el-input v-model="ruleForm.newPass"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="surePass">
            <el-input v-model="ruleForm.surePass"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
    </el-form>
</div>
</template>

<script>
export default {
    data() {
        return {
            ruleForm: {
                oldPass: '',
                newPass: '',
                surePass: '',
            },
            rules: {
                oldPass: [{
                    required: true,
                    message: '请输入原密码',
                    trigger: 'blur'
                }, ],
                newPass: [{
                    required: true,
                    message: '请输入新密码',
                    trigger: 'blur'
                }],
                surePass: [{
                    required: true,
                    message: '请再次输入新密码',
                    trigger: 'blur'
                }],

            }
        };
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    alert('submit!');
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        }
    }
}
</script>
